<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let x = 3,
            obj = {
                x: 5
            };
        obj.fn = (function () {
            this.x *= ++x;
            return function (y) {
                this.x *= (++x) + y;
                console.log(x);
            }
        })();

        let fn = obj.fn;
        obj.fn(6);//5
        fn(4);
        console.log(obj.x, x, window.x);
    </script>
</body>

</html>